/*
pthread_barrier_init()
pthread_barrier_wait()
pthread_barrier_destroy()
*/


#include<iostream>
#include<pthread.h>

using namespace std;


pthread_barrier_t barrier;

void* waitBarrier(void* arg)
{
	cout << "wait at barrier" << endl;
	pthread_barrier_wait(&barrier);
	cout << "pass the barrier" << endl;

	return nullptr;
}



int main(int argc,char**argv)
{
	pthread_t t1,t2,t3;

	pthread_barrier_init(&barrier,nullptr,3);

	pthread_create(&t1,nullptr,waitBarrier,nullptr);
	pthread_create(&t2,nullptr,waitBarrier,nullptr);
	pthread_create(&t3,nullptr,waitBarrier,nullptr);

	pthread_join(t1,nullptr);
	pthread_join(t2,nullptr);
	pthread_join(t3,nullptr);

	pthread_barrier_destroy(&barrier);	

	return 0;
}
